<template>
  <div>
    <p>选择审批人：
      <a-checkbox v-for="(i,index) in user" :key="i.id" :disabled="i.yxz" v-if="i.id!=l_id"
                  v-model="i.value" @change="onChangess(i.id, index, i.value)">{{i.username}}</a-checkbox>
    </p>
    <p>{{now_xz}}</p>
    <p>{{Approved_list}}</p>
    <button @click="bingshen">并审</button><button @click="chuanshen">串审</button>
    <p v-for="(j,k,index) in mbs">
      <span v-if="j=='text'">{{ k }}：<input type="text" v-model="mb[k]"></span>
      <span v-if="j=='date'">{{ k }}：<a-date-picker @change="onChange => xz(onChange,k)"/></span>
    </p>
  
    <br><br><br>
    <button @click="tj">提交</button>
  </div>
</template>

<script>
import 'moment/locale/zh-cn';
import mycate from "./diguizhanshi_zi";

export default {
  name: "gongdanlx",
  data() {
    return {
      mb: '',
      mbs: '',
      user: [],
      pid: this.$route.query.pid,
      Approved_list: [],
      file: '',
      now_xz: [],
      l_id: sessionStorage.getItem('uid')
    }
  },
  components: {
    mycate
  },
  methods: {
    onChange(data, string) {
      console.log(data, string)
    },
    handleChange(value) {
      this.Approved_list.push(value)
      for (var i of this.user) {
        if (i.id === value) {
          i.yxz = true
        }
      }
    },
    xz(date, k) {
      this.mb[k] = date._d
    }
    ,
    qq() {
      this.axios.get('http://127.0.0.1:8000/qingjia/?pid=' + this.pid)
        .then(resp => {
          this.mb = resp.data.mb
          this.mbs = resp.data.mbs
          this.user = resp.data.user
          for (var j of this.user) {
            j['yxs'] = false
            j['value'] = false
          }
          for (var i in this.mb) {
            this.mb[i] = ''
          }
        })
    },
    tj() {
      console.log(this.Approved_list)
      var data = new FormData()
      data.append('voucher', this.file)
      data.append('uid', sessionStorage.getItem('uid'))
      data.append('Approved_list', JSON.stringify(this.Approved_list))
      data.append('info', JSON.stringify(this.mb))


      this.axios.post('http://127.0.0.1:8000/qingjia/?pid=' + this.pid, data).then(resp => {
        console.log(resp.data.data)
      })
    },
    onChangess(e, index, value) {
      if(this.now_xz.indexOf(e)==-1){
        this.now_xz.push(e)
      }else {
        this.now_xz.splice(this.now_xz.indexOf(e), 1)
      }
      this.user.yxz = false
    },
    bingshen(){
      for(var i of this.user){
        if(this.now_xz.indexOf(i.id)!=-1){
          i.yxz = true
        }
      }
      this.Approved_list.push(this.now_xz)
      this.now_xz=[]
    },
    chuanshen(){
      for(var i of this.now_xz){
        this.Approved_list.push(i)
      }
      this.now_xz = []
      for(var j of this.user){
        if(this.Approved_list.indexOf(j.id)!=-1){
          j.yxz = true
        }
      }
    }
  },
  mounted() {
    this.qq()
  }
}
</script>

<style scoped>

</style>